package com.bagelly.mvvm.common

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter

/**
 *
 * @ProjectName: MyMVVM
 * @Package: com.bagelly.mvvm.common
 * @ClassName: SimpleFragmentPageAdapter
 * @Description: java类作用描述
 * @Author: bagelly
 * QQ:774169396
 * @CreateDate: 2020/6/10 下午2:28
 */

open class SimpleFragmentPageAdapter(
    fm: FragmentManager,
    private val fragments:List<Fragment>,
    private val titles:List<CharSequence>?=null
):FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
    init {
        require(!(titles!=null&&titles.size!=fragments.size)){
            "Fragments and titles list size msut match"
        }
    }
    override fun getCount(): Int =fragments.size
    override fun getItem(position: Int): Fragment=fragments[position]
    override fun getItemId(position: Int): Long =fragments[position].hashCode().toLong()
    override fun getPageTitle(position: Int): CharSequence?=titles?.get(position)
}